package com.ymatou.iapi.couponactivity.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponactivity.parameter.CheckUserIsReceivedBean;
import com.ymatou.iapi.couponactivity.parameter.ReceiveCouponBean;
import com.ymatou.iapi.couponactivity.service.CheckUserIsReceivedCall;
import com.ymatou.iapi.couponactivity.service.ReceiveCouponCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponActivityService;
import com.ymttest.database.model.YmtCouponActivity;
import com.ymttest.database.sqlwapper.YmtCouponActivityWapper;
import com.ymttest.utils.TestDataManager;

/**
 * 检验用户是否领取过优惠券用例 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CheckUserIsReceived {
	private static CheckUserIsReceivedBean checkuserisreceivedBean;
	private static CheckUserIsReceivedCall checkuserisreceivedCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检验用户是否领取过优惠券用例");
	}

	@Before
	public void caseUp() {
		checkuserisreceivedBean = new CheckUserIsReceivedBean();
		checkuserisreceivedCall = new CheckUserIsReceivedCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkuserisreceivedCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_CheckUserIsReceived_001() {
		Logger.start(true, "反例-活动不存在");
		try {
			checkuserisreceivedBean.setActivityCode(33444);
			checkuserisreceivedBean.setDeviceNumber("12233");
			checkuserisreceivedBean.setMobile("18611111111");
			checkuserisreceivedBean.setUserId(123456);
			
			checkuserisreceivedCall.setData(checkuserisreceivedBean);
			checkuserisreceivedCall.callService();

			Logger.verifyEquals("10001", checkuserisreceivedCall.getCode(), "验证返回StatusCode");
			Logger.verifyEquals("活动不存在", checkuserisreceivedCall.getMessage(), "验证返回Message");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CheckUserIsReceived_002() {
		Logger.start(true, "正例-检验用户是否领取过优惠券-领取过");
		try {
			ReceiveCouponBean receivecouponBean = new CouponActivityService().setReceiveCouponBean();
			ReceiveCouponCall receivecouponCall = new CouponActivityService().ReceiveCoupon(receivecouponBean);
			
			checkuserisreceivedBean.setActivityCode(receivecouponBean.getActivityCode());
			checkuserisreceivedBean.setUserId(receivecouponBean.getUserId());
			checkuserisreceivedBean.setMobile(receivecouponBean.getMobile());
			checkuserisreceivedBean.setDeviceNumber(receivecouponBean.getDeviceId());			
			
			checkuserisreceivedCall.setData(checkuserisreceivedBean);
			checkuserisreceivedCall.callService();

			Logger.verifyEquals("0", checkuserisreceivedCall.getCode(), "验证返回StatusCode");
			Logger.verifyEquals("操作成功！", checkuserisreceivedCall.getMessage(), "验证返回Message");

			Logger.verifyEquals("true", checkuserisreceivedCall.getIsReceived(), "验证返回IsReceived");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_CheckUserIsReceived_003() {
		Logger.start(true, "正例-检验用户是否领取过优惠券-未领取过");
		try {
			YmtCouponActivity activity = new YmtCouponActivityWapper().selectCouponActivityByActivityChannel("common").get(0);
			
			String mobilePhone = TestDataManager.getRandomNum(11);	
			String deviceNumber = "Dev"+TestDataManager.getRandomNum(11);	
			int userId = 30000000+Integer.parseInt(TestDataManager.getRandomNum(7));
			
			checkuserisreceivedBean.setActivityCode(activity.getActivityCode());
			checkuserisreceivedBean.setDeviceNumber(deviceNumber);
			checkuserisreceivedBean.setMobile(mobilePhone);
			checkuserisreceivedBean.setUserId(userId);
			
			checkuserisreceivedCall.setData(checkuserisreceivedBean);
			checkuserisreceivedCall.callService();

			Logger.verifyEquals("0", checkuserisreceivedCall.getCode(), "验证返回StatusCode");
			Logger.verifyEquals("操作成功！", checkuserisreceivedCall.getMessage(), "验证返回Message");

			Logger.verifyEquals("false", checkuserisreceivedCall.getIsReceived(), "验证返回IsReceived");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}